package org.examplexx.mytestwebapplication.controller;
import org.apache.ibatis.annotations.Delete;
import org.examplexx.mytestwebapplication.pojo.Emp;
import org.examplexx.mytestwebapplication.pojo.PageBean;
import org.examplexx.mytestwebapplication.pojo.Result;
import org.examplexx.mytestwebapplication.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/emps")
public class EmpCotroller {
    @Autowired
    private EmpService empService;
    @GetMapping
    public Result page(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize, String name, Integer gender, @DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")LocalDateTime entrytime, @DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss") LocalDateTime endtime) {
        PageBean pageBean = empService.page(page,pagesize,name,gender, entrytime, endtime);
        Result result = new Result();
        result.success(pageBean);
        return result;
    }
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer>ids) {
        Result result = new Result();
        result.success();
        empService.deleteEmp(ids);
        return result;
    }
    @PostMapping
    public Result save(@RequestBody Emp emp) {
        empService.addEmp(emp);
        Result result = new Result();
        result.success();
        return result;
    }
}